<?php
/*
 * @Author: lokei
 * @Date: 2022-12-31 21:21:28
 * @LastEditors: lokei
 * @LastEditTime: 2022-12-31 22:57:44
 * @Description: 
 */

namespace App\Http\Controllers\Widget;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Middle\MenuMiddle;
use App\Models\Widget\MenuModel;
use Illuminate\Http\Request;

class MenuController extends Controller
{
    public function list()
    {
        $items = MenuModel::get();
        if (count($items) == 0) {
            MenuMiddle::reset();
            $items = MenuModel::get();
        }
        $res = ResultTool::success();
        $res['data']['menu_list'] = $items;
        return $res;
    }

    public function displayList(Request $request) {
        $items = MenuModel::where('display', '=', '1')->get();
        $res = ResultTool::success();
        $res['data']['items'] = $items;
        return $res;
    }
    public function update(Request $request) {
        $menu = MenuModel::where('id', '=', $request->input('id'))->first();
        $menu->name = $request->input('name');
		$menu->icon = $request->input('icon');
		$menu->icon_active = $request->input('icon_active');
		$menu->url = $request->input('url');
		$menu->wxapp_url = $request->input('wxapp_url');
		$menu->display = $request->input('display');
		$menu->active_only_icon = $request->input('active_only_icon');
        $menu->save();
        $res = ResultTool::success();
        $res['data']['status'] = '0';
        return $res;
    }
}
